package com.yyk.yykywd.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.TextView;

import com.orhanobut.logger.Logger;
import com.yyk.yykywd.BusinessPeopleInfoKt;
import com.yyk.yykywd.KotlinConstantKt;
import com.yyk.yykywd.R;
import com.yyk.yykywd.base.BaseActivity;
import com.yyk.yykywd.listenter.DialogSureCancelListenter;
import com.yyk.yykywd.mvvm.ui.ModifyPwdActivity;
import com.yyk.yykywd.mvvm.ui.UserAgreementActivity;
import com.yyk.yykywd.mvvm.view_model.ModifyPwdViewModel;
import com.yyk.yykywd.ui.login.LoginActivity;
import com.yyk.yykywd.util.DialogUtil;
import com.yyk.yykywd.util.FileCacheUtils;
import com.yyk.yykywd.util.OnClickFlagUtil;
import com.yyk.yykywd.util.SetTextStyleKt;
import com.yyk.yykywd.util.ToAnotherActivity;
import com.yyk.yykywd.util.ToastUtil;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 设置
 */
public class SetActivity extends BaseActivity {
    @Override
    public int getLayoutId() {
        return R.layout.activity_set;
    }

    @Override
    public void initView() {
        initToolbar();
    }

    @Override
    public void initData() {

    }

    private void initToolbar() {
        setBackArrow();
        setTitle("设置");
    }

    /**
     * 1.更改手机号
     * 2.清除缓存
     * 3.退出登录
     *
     * @param view
     */
    @OnClick({R.id.ll_changephone, R.id.ll_clearhc, R.id.bt_outlogin,
            R.id.ll_user_agreement, R.id.ll_privacy_policy,R.id.ll_modify_pwd})
    public void onViewClicked(View view) {
        if (OnClickFlagUtil.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.ll_changephone:
                startAct(ChangePhotonumberActivity.class);
                break;
            case R.id.ll_clearhc:
                DialogUtil.showReturnTips(this, null, "是否清除本地缓存？", "确定", "取消", new DialogSureCancelListenter() {
                    @Override
                    public void onSureListenter() {
//                        先来一个假的，不知道是否可用
//                        FileCacheUtils.cleanExternalCache(mActivity);
//                        initCacheSize();
                        ToastUtil.showShort(mActivity, "本地缓存清除成功");
                    }

                    @Override
                    public void onCancelListenter() {

                    }
                }, false);
                break;
            case R.id.bt_outlogin:
                DialogUtil.showReturnTips(this, null, "是否退出当前账户", "确定", "取消", new DialogSureCancelListenter() {
                    @Override
                    public void onSureListenter() {
                        BusinessPeopleInfoKt.deleteUserData();
                        Intent intent = new Intent(mActivity, LoginActivity.class);
                        finish();
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                    }

                    @Override
                    public void onCancelListenter() {

                    }
                }, false);
                break;
            case R.id.ll_user_agreement:
                ToAnotherActivity.INSTANCE.toAgreementActivity(mActivity, KotlinConstantKt.USER_AGREEMENT);
                break;
            case R.id.ll_privacy_policy:
                ToAnotherActivity.INSTANCE.toAgreementActivity(mActivity, KotlinConstantKt.PRIVACY_POLICY);
                break;
            case R.id.ll_modify_pwd:
                ToAnotherActivity.INSTANCE.toCommonActivity(mActivity, ModifyPwdActivity.class);
                break;
        }
    }

    /**
     * 缓存配置  不用显示
     */
    private void initCacheSize() {
    /*
    * 获取SD卡根目录：Environment.getExternalStorageDirectory().getAbsolutePath();
        外部Cache路径：/mnt/sdcard/android/data/com.xxx.xxx/cache 一般存储缓存数据（注：通过getExternalCacheDir()获取）
        外部File路径：/mnt/sdcard/android/data/com.xxx.xxx/files 存储长时间存在的数据
        （注：通过getExternalFilesDir(String type)获取， type为特定类型，可以是以下任何一种
                    Environment.DIRECTORY_MUSIC,
                    Environment.DIRECTORY_PODCASTS,
                     Environment.DIRECTORY_RINGTONES,
                     Environment.DIRECTORY_ALARMS,
                     Environment.DIRECTORY_NOTIFICATIONS,
                     Environment.DIRECTORY_PICTURES,
                      Environment.DIRECTORY_MOVIES. ）
    * */
        String sdPath = Environment.getExternalStorageDirectory().getAbsolutePath();
        File outCachePath = mActivity.getExternalCacheDir();
        File outFilePath = mActivity.getExternalFilesDir(Environment.DIRECTORY_ALARMS);
        try {
            String outCacheSize = FileCacheUtils.getCacheSize(outCachePath);
            String outFileSize = FileCacheUtils.getCacheSize(outFilePath);

            Logger.e("缓存outCacheSize：" + outCacheSize);
            Logger.e("缓存outFileSize：" + outFileSize);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
